package inno.treeRepro;

import inno.specificOperator.Operator;
import inno.specificValue.Value;

public class Node {
	private Value valueOperator = null;
	private Operator myOperator = null;
	private Node leftNode = null;
	private Node rightNode = null;
	private int level;
	private String tag;
	private int posInLine;
	
	// constructor
	public Node(Value value, Operator myOperator) {
		this.valueOperator = value;
		this.myOperator = myOperator;
		if (null==value){
			tag = myOperator.getTag();
		}
		else{
			tag = value.getTag();
		}
		level = 0;
		posInLine = 0;
	}
	
	//c.constructor
	public Node(Node other){
		valueOperator = other.getValueOperator();
		myOperator = other.getMyOperator();
		level = other.getLevel();
		posInLine = other.getPosInLine();
		tag = new String(other.getTag());
		
		if (null!=other.getLeftSon()){
			leftNode = new Node(other.getLeftSon());
		}
		else{
			leftNode = null;
		}
		
		if (null!=other.getLRightSon()){
			rightNode = new Node(other.getLRightSon());
		}
		else{
			rightNode = null;
		}
	}
	
	public void setLeftNode(Node leftNode) {
		this.leftNode = leftNode;
	}

	public void setRightNode(Node rightNode) {
		this.rightNode = rightNode;
	}

	public Node getLeftSon(){
		return leftNode;
	}
	public Node getLRightSon(){
		return rightNode;
	}
	
	// value node dont have a right son	
	public boolean isSingleNoded(){
		if (null==rightNode){
			return true;
		}
		else{
			return false;
		}
	}
	
	// simple const dont have also a left son
	public boolean isLeaf() {
		//if (null==myOperator){
		if (null==leftNode){
			return true;
		}
		else{
			return false;
		}
	}

	public Operator getOperator(){
		return myOperator;
	}

	public int getLevel() {
		return level;
	}

	public void setLevel(int level) {
		this.level = level;
	}

	public Value getValueOperator() {
		return valueOperator;
	}

	public void setValueOperator(Value valueOperator) {
		this.valueOperator = valueOperator;
		if (null!=valueOperator){
			tag = valueOperator.getTag();
		}
	}

	public void setPosInLine(int posInLine) {
		this.posInLine = posInLine;
	}

	public Operator getMyOperator() {
		return myOperator;
	}

	public void setMyOperator(Operator myOperator) {
		this.myOperator = myOperator;
		if (null!=myOperator){
			tag = myOperator.getTag();
		}
	}

	public Double getValue(int param) {
		Double value = valueOperator.getValue(param);
		return value;
	}
	
	public String getTag(){
		return new String(tag);
	}
	
	public int getPosInLine(){
		return posInLine;
	}

}
